package com.hzzh.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hzzh.util.ConnectionFactory;

public class CounterDAO {
	private Connection conn;
	//更新
		public void update(int visitcount) throws ClassNotFoundException, SQLException{
			conn=ConnectionFactory.getConnection();
			String sql="update counter set visitcount=?";
		
				PreparedStatement pstmt=conn.prepareStatement(sql);
				pstmt.setInt(1, visitcount);
				pstmt.executeUpdate();
				pstmt.close();
				conn.close();
			}
		
		public int select() throws ClassNotFoundException, SQLException{
			int visitcount=0;
			conn=ConnectionFactory.getConnection();
			String sql="select* from counter";
			PreparedStatement pstmt=conn.prepareStatement(sql);
			ResultSet rs=pstmt.executeQuery();
			if(rs.next()){
				visitcount =rs.getInt("visitcount");
			}
			rs.close();
			pstmt.close();
			conn.close();
			return visitcount;
		}
}
